/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.ieslaferreria.creditsintesis.rmi;

import edu.ieslaferreria.creditsintesis.logicgame.actions.AddRemotePlayerEvent;
import edu.ieslaferreria.creditsintesis.logicgame.actions.ChangedLocationEvent;
import edu.ieslaferreria.creditsintesis.logicgame.actions.ConfigurationEvent;
import edu.ieslaferreria.creditsintesis.logicgame.actions.RmiEvent;
import java.rmi.RemoteException;
import java.util.HashMap;

/**
 * clase de cliente temporal para hacer alguna modificación de Client
 * @author Administrador
 */
public class Client_1 {
    private String nom;
    private Pont pont;
    private Pont pontInt;
    private int kindPanel; /*kind of panel that it needs*/
    private boolean resp; /* if this is the answer player or the questioner*/

    private EventRemoteListener listener;
    private EventConfiguracioListener listenerConfiguracio;
    private EventLocationListener listenerLocation;
    private EventStateListener listenerState;
    private EventAddRemotePlayerListener listenerRemotePlayer;
    private EventPanelsInteractionListener listenerPanel;

// por hacer-- añadir todos los listeners en Hashmap
   
    private HashMap<String,EventRemoteListener> listeners;



    /** Creates a new instance of Interlocutor */
    public Client_1(String nom) throws RemoteException {
        this.setListener(new EventRemoteListener (){
            public void action(RmiEvent event)throws RemoteException{
                onMessage(event);
                System.out.println("Nombre de la clase del evento" + event.getClass().getName());
            }

        });
        this.nom = nom;
    }

    private void onMessage(RmiEvent mess) throws RemoteException{
        if(mess instanceof ConfigurationEvent){
            getListenerConfiguracio().action(mess);
        }else if(mess instanceof ChangedLocationEvent){
            getListenerLocation().action(mess);
        }else if(mess instanceof AddRemotePlayerEvent){ /*???????????????????????????????*/
            System.out.println("onMessage con AddRemote Player");
            getListenerRemotePlayer().action(mess);
        }else if(mess instanceof EventGoInListener){
            getListenerPanel().action(mess);
        }else{
            getListenerState().action(mess);
        }
    }

    public void creaPartida(PontServer server, boolean flag) throws RemoteException{
            this.setPont(server.createPartida(new PontImpl(this.getListener(),this.getNom()), this.getNom(), flag));
    }



    public void send(RmiEvent mes)throws RemoteException{
        this.getPont().send(mes);
    }

    /**
     * @return the listenerConfiguracio
     */
    public EventConfiguracioListener getListenerConfiguracio() {
        return listenerConfiguracio;
    }

    /**
     * @param listenerConfiguracio the listenerConfiguracio to set
     */
    public void setListenerConfiguracio(EventConfiguracioListener listenerConfiguracio) {
        this.listenerConfiguracio = listenerConfiguracio;
    }

    /**
     * @return the listenerLocation
     */
    public EventRemoteListener getListenerLocation() {
        return listenerLocation;
    }

    /**
     * @param listenerLocation the listenerLocation to set
     */
    public void setListenerLocation(EventLocationListener listenerLocation) {
        this.listenerLocation = listenerLocation;
    }

    /**
     * @return the listenerState
     */
    public EventRemoteListener getListenerState() {
        return listenerState;
    }

    /**
     * @param listenerState the listenerState to set
     */
    public void setListenerState(EventStateListener listenerState) {
        this.listenerState = listenerState;
    }

    /**
     * @return the listener
     */
    public EventRemoteListener getListener() {
        return listener;
    }

    /**
     * @param listener the listener to set
     */
    public void setListener(EventRemoteListener listener) {
        this.listener = listener;
    }
    
    public Pont getPont(){
        return this.pont;
        //return new PontImpl(listener, nom);
    }

    public Pont getPontInteracction(){
        return this.pontInt;

    }

    /**
     * @return the nom
     */
    public String getNom() {
        return nom;
    }

    /**
     * @param nom the nom to set
     */
    public void setNom(String nom) {
        this.nom = nom;
    }

    /**
     * @param pont the pont to set
     */
    public void setPont(Pont pont) {
        this.pont = pont;
    }

     public void setPontInterracction(Pont pontI) {
        this.pontInt = pontI;
    }

    /**
     * @return the listenerRemotePlayer
     */
    public EventAddRemotePlayerListener getListenerRemotePlayer() {
        return listenerRemotePlayer;
    }
    /**
     * @return the kindPanel
     */
    public int getKindPanel() {
        return kindPanel;
    }
    /**
     * @param listenerRemotePlayer the listenerRemotePlayer to set
     * only for Server
     */
    public void setListenerRemotePlayer(EventAddRemotePlayerListener listenerRemotePlayer) {
        this.listenerRemotePlayer = listenerRemotePlayer;
    }
    /**
     * @param kindPanel the kindPanel to set
     */
    public void setKindPanel(int kindPanel) {
        this.kindPanel = kindPanel;
    }

    /**
     * @return the resp
     */
    public boolean isResp() {
        return resp;
    }



    /**
     * @param resp the resp to set
     */
    public void setResp(boolean resp) {
        this.resp = resp;
    }

    /**
     * @return the listenerPanel
     */
    public EventPanelsInteractionListener getListenerPanel() {
        return listenerPanel;
    }

    /**
     * @param listenerPanel the listenerPanel to set
     */
    public void setListenerPanel(EventPanelsInteractionListener listenerPanel) {
        this.listenerPanel = listenerPanel;
    }


    public EventRemoteListener getListener(EventRemoteListener event){
        return this.listeners.get(event.getClass().getName());
    }

}
